/**
 * 初始化商机管理详情对话框
 */
var BopportunitiesInfoDlg = {
    bopportunitiesInfoData : {}
};

/**
 * 清除数据
 */
BopportunitiesInfoDlg.clearData = function() {
    this.bopportunitiesInfoData = {};
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
BopportunitiesInfoDlg.set = function(key, val) {
    this.bopportunitiesInfoData[key] = (typeof val == "undefined") ? $("#" + key).val() : val;
    return this;
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
BopportunitiesInfoDlg.get = function(key) {
    return $("#" + key).val();
}

/**
 * 关闭此对话框
 */
BopportunitiesInfoDlg.close = function() {
    parent.layer.close(window.parent.Bopportunities.layerIndex);
}

/**
 * 收集数据
 */
BopportunitiesInfoDlg.collectData = function() {
    this
    .set('id')
    .set('name')
    .set('nstatus')
    .set('industry')
    .set('province')
    .set('city')
    .set('area')
    .set('sizes')
    .set('team')
    .set('salesman')
    .set('potential')
    .set('amount')
    .set('amounttime')
    .set('astatus')
    .set('cproperty')
    .set('countrys')
    .set('ctype')
    .set('clevel')
    .set('pprocess')
    .set('dess')
    .set('inumber')
    .set('addres')
    .set('iphones')
    .set('opens')
    .set('acc')
    .set('oadds')
    .set('oemail')
    .set('wsite');
}

/**
 * 提交添加
 */
BopportunitiesInfoDlg.addSubmit = function() {

    this.clearData();
    this.collectData();

    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/bopportunities/add", function(data){
        Feng.success("添加成功!");
        window.parent.Bopportunities.table.refresh();
        BopportunitiesInfoDlg.close();
    },function(data){
        Feng.error("添加失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.bopportunitiesInfoData);
    ajax.start();
}

/**
 * 提交修改
 */
BopportunitiesInfoDlg.editSubmit = function() {

    this.clearData();
    this.collectData();

    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/bopportunities/update", function(data){
        Feng.success("修改成功!");
        window.parent.Bopportunities.table.refresh();
        BopportunitiesInfoDlg.close();
    },function(data){
        Feng.error("修改失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.bopportunitiesInfoData);
    ajax.start();
}

$(function() {
    $("#pprocess").val($("#pprocessValue").val());
    $("#dess").val($("#dessValue").val());
    $("#nstatus").val($("#nstatusValue").val());
    $("#industry").val($("#industryValue").val());
    $("#sizes").val($("#sizesValue").val());
    $("#astatus").val($("#astatusValue").val());
    $("#cpropertys").val($("#cpropertysValue").val());
    $("#countrys").val($("#countrysValue").val());
    $("#ctype").val($("#ctypeValue").val());

});
